<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="/struts-html" prefix="html" %>
<%@ taglib uri="/struts-bean" prefix="bean" %>
<%@ taglib uri="/struts-logic" prefix="logic" %>
<%@ taglib uri="/struts-nested" prefix="nested" %>
<%@ taglib uri="/terasoluna-struts" prefix="ts" %>
<%@ taglib uri="/terasoluna" prefix="t" %>
<%@ taglib uri="/terasoluna-library" prefix="tl" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String imagePath = basePath + "admin/images";
%>
<html:html>
<head>
<title></title>
<link href="<%=request.getContextPath()%>/admin/css/tcmsystem.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" type="text/css" href="<%=basePath %>admin/javascript/uploadify/uploadify.css"/>
<script type="text/javascript" src="<%=basePath %>/admin/javascript/jquery-1.7.1.js"></script>
<script type="text/javascript" src="<%=basePath %>/admin/javascript/uploadify/swfobject.js"></script>
<script type="text/javascript" src="<%=basePath %>/admin/javascript/uploadify/jquery.uploadify.v2.0.3.js"></script> 
<script type="text/javascript">
       $(document).ready(function() {
           $("#file").uploadify({
               // 如果需要修改按钮的图片：可以使用'buttonImg'配置进行替换 
               'uploader'       : '<%=basePath%>admin/javascript/uploadify/uploadify.swf',
               'buttonImg'      : '<%=basePath%>admin/javascript/uploadify/select.png',
               'script'         : '<%=basePath%>uploadAction.do',
               'cancelImg'      : '<%=basePath%>admin/javascript/uploadify/cancel.png',
               'height'         : 32,//上传按钮的高和宽
               'width'          : 95,
               'queueID'        : 'fileQueue',
               'fileDataName'   : 'file',
               'auto'           : false,
               'multi'          : true,
               'queueSizeLimit' : 3,
               'fileDesc'       : '*.*',
               'fileExt'        : '*.*',
	        onComplete: function (event, queueID, fileObj, response, data) {
	        	onComplete(response);
			},
			onError: function(event, queueID, fileObj) {
				alert("文件:" + fileObj.name + "上传失败");
			},
			onCancel: function(event, queueID, fileObj){
				alert("取消了" + fileObj.name);
			}
           });
       });
       
    function onComplete(response) {
    	var jsonObj = eval(response)[0];
    	var picId = jsonObj.fileid;
    	var path = jsonObj.relativePath;
    	var imageName = jsonObj.fileName;
    	if ($('#enterprisePicture').val() == "") {
    		$('#enterprisePicture').val(picId);
    	} else {
    		$('#enterprisePicture').val($('#enterprisePicture').val() + "," + picId);
    	}
    	
    	var imagePath =  path + imageName;
    	var html = '';
    	$html = '<div id="img_' + picId + '">';
    	$html += '<img src="<%=basePath%>'+ imagePath +'" width="80" height="80" style="margin:5px;">';
    	$html += '<a href="#" onClick="deletePic(\'' + picId + '\')">删除</a>';
    	$html += '</div>';
    	$('#imageinfo').append($html);
    }
    
    function deletePic(picId) {
    	$.ajax({
            type: "post",
            url: "<%=basePath%>deleteImgAction.do",
            data: "picId=" + picId,
            success: function (result) {
            	$('#img_' + picId).remove();
            	// 删除Hidden中的picid
        		var afterValue = $('#enterprisePicture').val().replace(picId + ",", '').replace("," + picId , '').replace(picId, '');
        		$('#enterprisePicture').val(afterValue);
            }
        });
    }
</script>
</head>
<body>
<ts:form action="/addEstate.do" method="POST" enctype="multipart/form-data">
<table width="60%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="30" background="<%=imagePath%>/tab_05.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="12" height="30"><img src="<%=imagePath%>/tab_03.gif" width="12" height="30" /></td>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="46%" valign="middle"><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="5%"><div align="center"><img src="<%=imagePath%>/tb.gif" width="16" height="16" /></div></td>
                <td width="95%" class="STYLE1"><span class="STYLE3">你当前的位置</span>：[园区企业]-[房地产]</td>
              </tr>
            </table></td>
          </tr>
        </table></td>
        <td width="16"><img src="<%=imagePath%>/tab_07.gif" width="16" height="30" /></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="8" background="<%=imagePath%>/tab_12.gif">&nbsp;</td>
        <td><table width="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="b5d6e6">
          <tr>
            <td width="20%" height="30" align="center" bgcolor="#FFFFFF" class="STYLE1">房地产企业名称
            </td>
            <td width="80%" height="30" bgcolor="#FFFFFF" class="STYLE1">
            <html:text property="estate.enterpriseName" size="30"></html:text>
            <span class="errorStyle"><ts:errors property="estate.enterpriseName"/></span>
            </td>
          </tr>
          <tr>
            <td width="20%" height="100" align="center" bgcolor="#FFFFFF" class="STYLE1">企业简介</td>
            <td width="80%" height="100" bgcolor="#FFFFFF" class="STYLE1">
            <html:textarea property="estate.overview" styleId="overview" cols="40" rows="10"></html:textarea>
            </td>
          </tr>
          <tr>
            <td width="20%" height="100" align="center" bgcolor="#FFFFFF" class="STYLE1">上传企业图片</td>
            <td width="80%" height="100" bgcolor="#FFFFFF" class="STYLE1" valign="top">
            <html:hidden property="estate.enterprisePicture" styleId="enterprisePicture"/>
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
            	<tr>
	            	<td width="100%">
	            	    <input type="file" name="file" id="file" />
	            	    <img src="<%=basePath%>admin/javascript/uploadify/upload.png" onClick="$('#file').uploadifyUpload()">
	           			<img src="<%=basePath%>admin/javascript/uploadify/cancel_upload.png" onClick="$('#file').uploadifyClearQueue()">
	            	</td>
            	</tr>
            	<tr><td><div id="fileQueue"></div></td></tr>
            	<tr><td><div id="imageinfo"></div></td></tr>
            </table>
            </td>
          </tr>
           <tr>
            <td height="30" align="center" bgcolor="#FFFFFF" class="STYLE1" colspan="2">
            <html:submit value="追加"></html:submit>
            <input type="button" value="返回上一页" onclick="location.href='./estateList.do'">
            </td>
          </tr>
        </table></td>
        <td width="8" background="<%=imagePath%>/tab_15.gif">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="35" background="<%=imagePath%>/tab_19.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="12" height="35"><img src="<%=imagePath%>/tab_18.gif" width="12" height="35" /></td>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td class="STYLE4">&nbsp;</td>
            <td></td>
          </tr>
        </table></td>
        <td width="16"><img src="<%=imagePath%>/tab_20.gif" width="16" height="35" /></td>
      </tr>
    </table></td>
  </tr>
</table>
</ts:form>
</body>
</html:html>
